home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / debug.h < prev    next >
C/C++ Source or Header  |  2001-06-08  |  2KB  |  63 lines

  1. /* Copyright (C) 2000 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: debug.h,v 1.11 2001/01/23 20:23:12 drscholl Exp $ */
  6.  
  7. #ifndef debug_h
  8. #define debug_h
  9.  
  10. #if DEBUG
  11.  
  12. #define ALLOC_BYTE 0xAA        /* allocated memory is filled with this value */
  13. #define END_BYTE 0xEE        /* written at the end of each block to detect
  14.                    buffer overrun */
  15. #define FREE_BYTE 0xFF        /* memory is filled with this prior to free */
  16.  
  17. #include <stdio.h>
  18. #define ASSERT(x) {if(!(x)){printf("assertion failed in %s, line %d: %s\n",__FILE__,__LINE__,#x);}}
  19. #define ASSERT_RETURN_IF_FAIL(x,r) {if(!(x)){printf("assertion failed in %s, line %d: %s\n",__FILE__,__LINE__,#x);return(r);}}
  20.  
  21. #include <sys/types.h>
  22.  
  23. #define INIT debug_init
  24. #define FREE(p) debug_free(p,__FILE__,__LINE__)
  25. #define MALLOC(s) debug_malloc(s,__FILE__,__LINE__)
  26. #define REALLOC(p,s) debug_realloc(p,s,__FILE__,__LINE__)
  27. #define CALLOC(n,s) debug_calloc(n,s,__FILE__,__LINE__)
  28. #define STRDUP(s) debug_strdup(s,__FILE__,__LINE__)
  29. #define CLEANUP debug_cleanup
  30. #define VALID(p) debug_valid(p,1)
  31. #define VALID_LEN debug_valid
  32. #define VALID_STR(p) debug_valid(p,strlen(p)+1)
  33. #define MEMORY_USED debug_usage()
  34.  
  35. /* internal functions, DO NOT CALL DIRECTLY -- use the above macros */
  36. void debug_init (void);
  37. void debug_free (void *, const char *, int);
  38. void *debug_malloc (int, const char *, int);
  39. void *debug_calloc (int, int, const char *, int);
  40. void *debug_realloc (void *, int, const char *, int);
  41. char *debug_strdup (const char *, const char *, int);
  42. void debug_cleanup (void);
  43. int debug_valid (void *, int);
  44. int debug_usage (void);
  45.  
  46. #else
  47.  
  48. #define INIT()
  49. #define FREE free
  50. #define MALLOC malloc
  51. #define CALLOC calloc
  52. #define REALLOC realloc
  53. #define STRDUP strdup
  54. #define CLEANUP()
  55. #define VALID(p)
  56. #define VALID_LEN(p,l)
  57. #define ASSERT(p)
  58. #define MEMORY_USED 0
  59.  
  60. #endif /* DEBUG */
  61.  
  62. #endif /* debug_h */
  63.